home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / sspell14.zip / CFGLOAD.C < prev    next >
C/C++ Source or Header  |  1992-07-06  |  5KB  |  147 lines

  1. /* **************************************************************** */
  2. /*             sspell - similar to Unix spell                       */
  3. /*                        version 1.4                               */
  4. /*                                                                  */
  5. /* Author: Maurice Castro                                           */
  6. /* Release Date:  4 Jul 1992                                         */
  7. /* Bug Reports: maurice@bruce.cs.monash.edu.au                      */
  8. /*                                                                  */
  9. /* This code has been placed by the Author into the Public Domain.  */
  10. /* The code is NOT covered by any warranty, the user of the code is */
  11. /* solely responsible for determining the fitness of the program    */
  12. /* for their purpose. No liability is accepted by the author for    */
  13. /* the direct or indirect losses incurred through the use of this   */
  14. /* program.                                                         */
  15. /*                                                                  */
  16. /* Segments of this code may be used for any purpose that the user  */
  17. /* deems appropriate. It would be polite to acknowledge the source  */
  18. /* of the code. If you modify the code and redistribute it please   */
  19. /* include a message indicating your changes and how users may      */
  20. /* contact you for support.                                         */
  21. /*                                                                  */
  22. /* The author reserves the right to issue the official version of   */
  23. /* this program. If you have useful suggestions or changes for the  */
  24. /* code, please forward them to the author so that they might be    */
  25. /* incorporated into the official version                           */
  26. /*                                                                  */
  27. /* Please forward bug reports to the author via Internet.           */
  28. /*                                                                  */
  29. /* **************************************************************** */
  30.  
  31. #include <stdio.h>
  32. #include "strfn.h"
  33. #include "config.h"
  34. #include "stop.h"
  35.  
  36. /* fix up some slash problems with MS-DOS */
  37. #ifdef __MSDOS__
  38. extern void dosfix();
  39. #endif
  40.  
  41. extern char dictpath[];
  42. extern char dictionary[];
  43. extern char rule[];
  44. extern char indexarr[];
  45. extern char sort[];
  46. extern char stop[];
  47.  
  48. /* load options from configuration file */
  49. void cfgload(cfgname)
  50. char *cfgname;
  51. {
  52.    char cfgline[MAXSTR];
  53.    FILE* cfgfile;
  54.    char *key;
  55.    char *value;
  56.  
  57.    if ( (cfgfile = fopen(cfgname,"r")) != (FILE *)NULL ) {
  58.       /* obtain new defaults from config file */
  59.       while (fgets(cfgline,MAXSTR,cfgfile)) {
  60.          if (cfgline[0]=='#')
  61.             continue;
  62.          key = strtok(cfgline," \t\r\n\"'");
  63.          if (key == (char *)NULL)
  64.             continue;
  65.          value = strtok((char *)NULL,"\t\r\n\"'");
  66.          if (value == (char *)NULL) {
  67.             fprintf(stderr,"No value for config option: %s\n",key);
  68.             continue;
  69.          }
  70.          if (!strcmp(key, "DICT_PATH")) {
  71.             strcpy(dictpath, value);   
  72.             /* if there is a path, and it does not end in a separator make it */
  73.             if ( strlen(dictpath) && 
  74.                 strcmp(dictpath+strlen(dictpath)-strlen(SEPARATOR), SEPARATOR))
  75.                strcat(dictpath, SEPARATOR);     /* add a separator */
  76. #ifdef __MSDOS__
  77.             dosfix(dictpath);
  78. #endif
  79.             }   
  80.          else if (!strcmp(key, "DICTIONARY")) {
  81.             if (strstr(value, SEPARATOR))
  82.                strcpy(dictionary, value);   
  83.             else {
  84.                strcpy(dictionary, dictpath);
  85.                strcat(dictionary, value);
  86.                }
  87.             }   
  88.          else if (!strcmp(key, "INDEX")) {
  89.             if (strstr(value, SEPARATOR))
  90.                strcpy(indexarr, value);   
  91.             else {
  92.                strcpy(indexarr, dictpath);
  93.                strcat(indexarr, value);
  94.                }
  95.             }   
  96.          else if (!strcmp(key, "RULE")) {
  97.             if (strstr(value, SEPARATOR))
  98.                strcpy(rule, value);   
  99.             else {
  100.                strcpy(rule, dictpath);
  101.                strcat(rule, value);
  102.                }
  103.             }   
  104.          else if (!strcmp(key, "STOP")) {
  105.             if (strstr(value, SEPARATOR))
  106.                strcpy(stop, value);   
  107.             else {
  108.                strcpy(stop, dictpath);
  109.                strcat(stop, value);
  110.                }
  111.             }   
  112.          else if (!strcmp(key, "SORT")) {
  113.             strcpy(sort, value);
  114.             }
  115.          else
  116.             fprintf(stderr,"Unknown config option: %s %s\n",key,value);
  117.          }
  118.       fclose(cfgfile);   
  119.       }
  120.       if (strlen(dictionary)==0) {
  121.           strcpy(dictionary, dictpath);
  122.           strcat(dictionary, DICTIONARY);
  123.       }
  124.       if (strlen(indexarr)==0) {
  125.           strcpy(indexarr, dictpath);
  126.           strcat(indexarr, INDEX);
  127.       }
  128.       if (strlen(rule)==0) {
  129.           strcpy(rule, dictpath);
  130.           strcat(rule, RULE);
  131.       }
  132.       if (strlen(stop)==0) {
  133.           strcpy(stop, dictpath);
  134.           strcat(stop, STOP);
  135.       }
  136.       if (strlen(sort)==0) {
  137.           strcpy(sort, SORT);
  138.       }
  139. #ifdef __MSDOS__
  140.       dosfix(dictionary);
  141.       dosfix(rule);
  142.       dosfix(indexarr);
  143.       dosfix(sort);
  144.       dosfix(stop);
  145. #endif
  146. }
  147.